package com.kaishengit.web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


import com.kaishengit.dao.EmployeeDao;
import com.kaishengit.entity.Employee;

public class LoginServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String name  = request.getParameter("username");
		String password = request.getParameter("password");
		
		
		if(name == null || password == null) {
			response.sendRedirect("index.jsp");
		}
		EmployeeDao dao = new EmployeeDao();
		Employee employee = dao.findByNameAndPwd(name,password);
		if(employee!=null) {
			HttpSession session = request.getSession();		
			session.setAttribute("empolyee", employee);
			response.sendRedirect("main.jsp");
		}
		
	}

}
